//
//  ViewController.m
//  GTVideoPlayerController
//
//  Created by yate1996 on 15/7/17.
//  Copyright (c) 2015年 yate1996. All rights reserved.
//

#import "ViewController.h"
#import <MediaPlayer/MediaPlayer.h>
@interface ViewController ()
@property (nonatomic , strong) MPMoviePlayerController *videoPlayer;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupMoviePlayer];

}
-(void)setupMoviePlayer
{
    MPMoviePlayerController *videoPlayer = [[MPMoviePlayerController alloc]init];
    videoPlayer.contentURL = [[NSBundle mainBundle]URLForResource:@"minion_01.mp4" withExtension:nil];
    //    videoPlayer.contentURL = [NSURL URLWithString:@"http://localhost:8080/MJServer/resources/videos/minion_02.mp4"];
    
    
    _videoPlayer = videoPlayer;
    [_videoPlayer prepareToPlay];
    videoPlayer.view.frame = CGRectMake(0, 20, [UIScreen mainScreen].bounds.size.width, 200);
    videoPlayer.shouldAutoplay = NO;
    [self.view addSubview:videoPlayer.view];
}
//全屏后，横屏自动改变视频方向
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
//    self.videoPlayer.view.frame = CGRectMake(0, 20, [UIScreen mainScreen].bounds.size.width, 200);

    if(self.interfaceOrientation == UIDeviceOrientationLandscapeLeft||self.interfaceOrientation == UIDeviceOrientationLandscapeRight)
    {
        [self.videoPlayer setFullscreen:YES animated:NO];
    }else
    {
        [self.videoPlayer setFullscreen:NO animated:NO];
        
    }
//    switch (toInterfaceOrientation) {
//        case UIInterfaceOrientationPortrait:
//            //home健在下
//            [self.videoPlayer setFullscreen:NO animated:NO];
//            self.videoPlayer.fullscreen = NO;
//            break;
//        case UIInterfaceOrientationPortraitUpsideDown:
//            //home健在上
//            [self.videoPlayer setFullscreen:NO animated:NO];
//            self.videoPlayer.fullscreen = NO;
//
//            break;
//        case UIInterfaceOrientationLandscapeLeft:
//            //home健在左
//            [self.videoPlayer setFullscreen:YES animated:YES];
//            break;
//        case UIInterfaceOrientationLandscapeRight:
//            //home健在右
//            [self.videoPlayer setFullscreen:YES animated:YES];
//
//            break;
//        default:
//            break;
//    }
}
/**
 *  控制播放页面屏幕方向只支持竖屏
 *
 *  @return NSUInteger
 */
-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

    [_videoPlayer prepareToPlay];
    
}

@end
